﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebInterface;
using WebReposity.Entities;

namespace WebServices
{
    public class LoginService : ILoginService
    {
        private readonly ILogger<LoginService> _logger;
        private readonly MyDbContext _myDbContext;

        public LoginService(ILogger<LoginService> logger,MyDbContext myDbContext)
        {
            _logger = logger;
            _myDbContext = myDbContext;
        }

        public async Task<bool> CheckUser(LoginUserEntity user)
        {
            //return await _myDbContext.Users.AnyAsync(i => i.Account == user.Account && i.Password == user.Password);


            var r = await _myDbContext.Users.AsNoTracking().FirstOrDefaultAsync(i=>i.Account==user.Account&&i.Password==user.Password);
            if (r==null)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
    }
}
